package com.loser.utils;


import com.loser.redis.core.RedisHandler;

/**
 * 锁工具
 *
 * @author alan
 * @date 2022/5/30 19:09
 */
public class LockUtil {

    /**
     * 业务包裹类
     */
    private static final BeanWrapper<RedisHandler> RedisHandlerWrapper = BeanWrapper.init(RedisHandler.class);

    public static boolean lock(String lockKey) {
        return lock(lockKey, lockKey, DateUtils.SECONDS_PER_MINUTE);
    }

    public static boolean lock(String lockKey, String lockValue) {
        return lock(lockValue, lockKey, DateUtils.SECONDS_PER_MINUTE);
    }

    public static boolean lock(String lockKey, String lockValue, long lockTime) {
        return RedisHandlerWrapper.getBean().lock(lockKey, lockValue, lockTime);
    }

    public static boolean releaseLock(String lockKey) {
        return releaseLock(lockKey, lockKey);
    }

    public static boolean releaseLock(String lockKey, String lockValue) {
        return RedisHandlerWrapper.getBean().releaseLock(lockKey, lockValue);
    }

}
